import { number } from 'echarts';
import request from '../utils/request';
import * as studentApi from '@/api/student';
import * as licenceApi from '@/api/licence';
import * as subjectApi from '@/api/subject';
import * as coachApi from '@/api/subject';
import * as processApi from '@/api/process';
import * as examApi from '@/api/exam';
import { coachItemData } from './coach';
const url = 'http://localhost:8080/exam';

export interface examItemData 
{
    examId : number;
    registDate : Date;
    examDate : Date;
    examScore : string;
    licenceId : number;
    studentId : number;
    subjectId : number;
    licence : licenceApi.licenceItemData;
    student : studentApi.studentItemData;
    subject : subjectApi.subjectItemData;
}

export const getCoachBySexOrAge = (sex: string, age1: number, age2: number) => {
    return request({
        url: url+'/getCoachBySexOrAge',
        method: 'post',
        params: { sex, age1, age2 }
    });
};
export const getAllCoach = () => {
    return request({
        url: url+'/getAllCoach',
        method: 'get',
    });
};

export const updateCoach = (coach : coachItemData) => {
    return request({
        url: url+`/updateCoach`,
        method: 'post',
        data : coach,
    });
};

export const filterCoach = (coach : coachItemData) => {
    return request({
        url: url+`/filterCoach`,
        method: 'post',
        data : coach,
    });
};

export const addCoach = (coach : coachItemData) => {
    return request({
        url: url+`/addCoach`,
        method: 'post',
        data : coach,
    });
};

export const deleteCoach = (coachId : string) => {
    return request({
        url: url+`/deleteCoach/`+coachId,
        method: 'delete',
    });
};

export const findByStudentID = (studentId : number) => {
    return request({
        url: url+`/findByStudentID/${studentId}`,
        method: 'get',
    });
};

export const findAllExam = () =>{
    return request({
        url: url+'/findAllExam',
        method: 'get',
    });
}

export const updateExam = (score: any, examId: any) => {
    const params = new URLSearchParams();
    params.append('score', score);
    params.append('id', examId.toString());
    return request({
        url: url + '/updateScore',
        method: 'post',
        params : params,
    });
}

export const findByCoachID = (coachId : any) => {
    return request({
        url: url+`/findByCoachID/${coachId}`,
        method: 'get',
    });
};

export const studentSignExam = (exam : any) =>{
    return request({
        url: url+`/addExam`,
        method: 'post',
        data : exam,
    });
}

export const findNewExam = (studentId : any) =>{
    return request({
        url: url+`/findNewExam/${studentId}`,
        method: 'get',
    });
}